<template>
  <div>
    <el-dialog
      title="编辑角色"
      :visible.sync="dialogVisible"
      width="25%"
    >
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="所属角色">
          <el-select v-model="form.pid" clearable placeholder="不选则默认为顶级角色">
            <el-option v-for="item in options"
                       :key="item.id"
                       :label="item.name"
                       :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="角色名称">
          <el-input v-model="form.name" style="width: 70%"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="handleOk">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
  import {createOrEditRole, getUpRoleList} from "@/api/sales";
  import {list} from "@/api/company";

  export default {
    name: "edit",
    data() {
      return {
        dialogVisible: false,
        options: [],
        form: {
          id: '',
          pid: '',
          name: ''
        }
      }
    },
    methods: {
      show(data) {
        this.form.id = data.id
        this.form.pid = data.pid
        this.form.name = data.name
        this.dialogVisible = true
        // getUpRoleList().then(res => {
        //   this.options = res.result
        // })
        let form = {
          page: 1,
          size: 99999,
        };
        list(form).then((res) => {
          this.options = res.result.records;
        });
      },
      handleOk() {
        createOrEditRole(this.form).then(res => {
          if (res.status === 200) {
            this.dialogVisible = false
            this.$message.success("编辑成功")
            this.$emit('Ok')
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
